<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="CSS/partie.css" />
<script language="javascript" src="js/ajax.js"></script>
<title>StarTrek - Partie</title>
</head>
<body>
	<c:if test="${monTour == true}">
		<h1>C'est votre tour de jouer !</h1>
	</c:if>
	<c:if test="${monTour == false}">
		<h1>C'est au tour de votre adversaire de jouer !</h1>
	</c:if>

	<div class="transbox">
		<p>${derniereAction}</p>
	</div>
	<table>
		<tr>
			<td>
				<table class="plateau">
					<c:set var="numLigne" value="1" />
					<c:forEach var="ligne" items="${monTableau}">
						<tr class="plateau">
							<td>${numLigne}</td>
							<c:forEach var="colonne" items="${ligne}">
								<td class="plateau"
									<c:if test="${colonne != null}">
							style="background-image: url('img/${colonne}.png'); background-repeat:no-repeat;"
							</c:if>></td>
							</c:forEach>
							<c:set var="numLigne" value="${numLigne+1}" />
						</tr>
					</c:forEach>
					<tr>
						<td></td>
						<c:forTokens items="A-B-C-D-E-F-G-H-I-J" delims="-" var="lettre">
							<td class="plateau_lettres">${lettre}</td>
						</c:forTokens>
					</tr>
				</table>
			</td>
			<td>
				<table class="plateau">
					<c:set var="numLigne" value="1" />
					<c:forEach var="ligne" items="${sonTableau}">
						<tr class="plateau">
							<td>${numLigne}</td>
							<c:set var="numColonne" value="1" />
							<c:forEach var="colonne" items="${ligne}">
								<td class="plateau"
									<c:if test="${monTour == true}">
									onClick="document.location.href='partieEnCours.html?x=${numColonne-1}&y=${numLigne-1}'; "
								</c:if>
									<c:if test="${colonne != null}">
							style="background-image: url('img/${colonne}.png'); background-repeat:no-repeat;"
							</c:if>></td>
								<c:set var="numColonne" value="${numColonne+1}" />
							</c:forEach>
							<c:set var="numLigne" value="${numLigne+1}" />
						</tr>
					</c:forEach>
					<tr>
						<td></td>
						<c:forTokens items="A-B-C-D-E-F-G-H-I-J" delims="-" var="lettre">
							<td class="plateau_lettres">${lettre}</td>
						</c:forTokens>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<c:if test="${monTour == false}">
		<script type="text/javascript">
			var ajax = new AjaxRequest("GET", "partieEnCours.html",
					"ajax=true", true, "");
			setInterval(function() {
				ajax.handleResponse = function() {
					if (ajax.xhr.response == "OK") {
						document.location.href = "partieEnCours.html";
					} else if (ajax.xhr.response == "KO") {
						document.location.href = "accueil.html?erreur=3";
					} else if (ajax.xhr.response == "WIN") {
						document.location.href = "accueil.html?message=1";
					} else if (ajax.xhr.response == "LOSE") {
						document.location.href = "accueil.html?message=2";
					}
				};
				ajax.process();
			}, 2000);
		</script>
	</c:if>
	<script type="text/javascript">
		setInterval(function() {
			document.location.href = "accueil.html?erreur=4";
		}, 330000);
	</script>
</body>
</html>